package com.lbb.simple.demo.controller

import com.lbb.http.HttpUtil
import com.lbb.http.call.CallBack
import com.lbb.mvp.presenter.BasePresenter
import com.lbb.mvp.view.BaseView
import com.lbb.simple.demo.bean.User
import com.lbb.simple.demo.http.Api
import com.lbb.simple.demo.utils.UserUtil
import com.lbb.utils.SpUtil

class UserController {
    class UserPresenter(view: UserView?) : BasePresenter<UserView>(view) {
        fun login(phone: String, password: String) {
            view?.showTopProgressDialog("登录中")
            HttpUtil.postForm(Api.login, mapOf("phone" to phone, "password" to password), object :
                CallBack<String> {
                override fun success(string: String) {
                    UserUtil.setUser(string)
                    view?.setUser(UserUtil.getUser())
                }

                override fun error(string: String) {
                    view?.showToast(string)
                }

                override fun complete() {
                    view?.dismissProgressDialog()
                }

            })
        }
    }

    interface UserView : BaseView {
        fun setUser(user: User?)
    }
}